
#include "MessageBoxCon.h"
#include "MsgBoxPainter.h"
#include "../Util/UtilInclude.h"

CMessageBoxCon::CMessageBoxCon(HWND hWnd):CContainer(hWnd)
{
	m_pBmpMask = NULL;
}

CMessageBoxCon::~CMessageBoxCon(void)
{
	if(m_pBmpMask)
	{
		delete m_pBmpMask;
	}
}

BOOL CMessageBoxCon::InitControls(DWORD dwData)
{
	//message box
	LANGUAGE_DECLARE;
	FONT_DECLARE;

	HBITMAP hBitmap = NULL;

	CResConfig ResCon;
	if(!ResCon.Init(L"MessageBox.xml"))
	{
		//g_App.ShowMsgBox(CMD_MSGBOX_OK,L"",LAN_GETTEXT(Msg_ResError));
		return FALSE;
	}

	m_nAniType  = ResCon.GetAniType();
	m_nAniSpeed = ResCon.GetAniSpeed();

	BOOL bFromDll = ResCon.IsResFromDll();
	BtnParam btnInfo;

	hBitmap = CUtil::LoadBitmapEx(ResCon.GetImage(),bFromDll);
	this->SetMaskBmp(hBitmap);

	BatTimePicParam picInfo;
	ResCon.GetBatTimePicParam(picInfo,L"Pic_Bkgnd");
	CPicture *pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"OK",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	TextParam txtInfo;
	ResCon.GetTextParam(txtInfo,L"Text_Msg");
	CText *pText = (CText*)AddControl(new CText(SWS_STATIC,m_strContent.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	if(m_strCaption.size()>0)
	{
		ResCon.GetTextParam(txtInfo,L"Title");
		pText = (CText*)AddControl(new CText(SWS_STATIC,m_strCaption.c_str(),txtInfo.m_rc, CMD_MSGBOX_TEXT));
		ResCon.SetTextParam(pText,txtInfo);
	}

	CBmpBtn* pBtn = NULL;
	if(CMD_MSGBOX_OK == dwData)
	{
		ResCon.GetBtnParam(btnInfo,L"Btn_OK");
		pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(Msg_OK),btnInfo.m_rc, CMD_MSGBOX_OK));
		ResCon.SetBtnParam(pBtn,btnInfo);
	}
	else
	{
		ResCon.GetBtnParam(btnInfo,L"Btn_Yes");
		pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(Msg_Yes),btnInfo.m_rc, CMD_MSGBOX_YES));
		ResCon.SetBtnParam(pBtn,btnInfo);
		
		ResCon.GetBtnParam(btnInfo,L"Btn_No");
		pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(Msg_No),btnInfo.m_rc, CMD_MSGBOX_NO));
		ResCon.SetBtnParam(pBtn,btnInfo);
	}

	SetPainter(new CMsgBoxPainter());
	return bRet;
}